package com.aimao.blog.config;

import com.aimao.blog.constant.ServerConst;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author PuaChen
 * @Create 2018-07-16
 */
public class BackGroundInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
        if (request.getSession().getAttribute(ServerConst.CURRENT_USER) == null) {
            response.sendError(401);
            return false;
        }
        return true;
    }


}
